<template>
  <div id="tab-bar-item" @click="itemClick">
    <div class="item-icon" v-show="!isActive"><slot name="icon"></slot></div>
    <div class="item-active-icon" v-show="isActive"><slot name="active-icon"></slot></div>
    <div class="item-text" :style="activeStyle"><slot name="text"></slot></div>
  </div>
</template>

<script>
	export default {
		name: "TabBarItem",
    props: {
			link: {
				type: String,
        required: true
      }
    },
    computed: {
			isActive() {
				return this.$route.path.indexOf(this.link) !== -1
      },
      activeStyle() {
				return this.isActive ? {'color': 'red'} : {}
      }
    },
    methods: {
			itemClick() {
        if(!this.isActive) {//非active状态才可以点击
          this.$router.replace(this.link)
        }
      }
    }
	}
</script>

<style lang='less' scoped>
  #tab-bar-item {
    flex: 1;
    .item-icon,.item-active-icon{
      margin-top: 0.1rem;
      height: .48rem;
      img{
        width:.48rem;
        height:.48rem;
        vertical-align:top;
      }
    }
    .item-text {
      font-size: .24rem;
      margin-top: 0.1em;
      color: #333;
    }
  }




</style>
